/**
 * 个人信息
 * Created by KY on 2017/4/17.
 */
define(['ldfw/core','text!tpl/user/index.tpl','weui','jweixin',
    'comps/ajax','comps/session','ldfw/ldlibs/dict','ldfw/helper/formatHelper'],
function (LDFW,tpl,weui,wx,ajax,session,dict) {
    return LDFW.Container.extend({
        tpl: tpl,
        initialize: function () {
            let curr_user = session.getCurrentUser()
            if (curr_user.cust_type === 1) {
                curr_user.risk_accept_label = dict.getDict('risk_accept_co', curr_user.risk_accept)
            } else {
                curr_user.risk_accept_label = dict.getDict('risk_accept_cust', curr_user.risk_accept)
            }
            this.model.set(curr_user)
            this.model.set('app_verify_type', app_verify_type)
            this.model.set('app_service_type', app_service_type)

            this.on('shown', function(){
                this.loadData()
            })
            this.loadData()
        },
        events: {
            'click a[operate="unbind"]': 'unbind',
            'click a[operate="logout"]':'logout'
        },
        loadData: function () {
            let curr_user = session.getCurrentUser()
            this.model.set(curr_user)
            this.loadNotification()
        },
        loadNotification: function () {
            const _this = this
            ajax.post('cpliL.3.22',{confirm_status: 2}).success(function (resp) {
                if (resp.result && resp.result.length) {
                    let length = resp.result.length
                    if(length>0){
                        _this.$el.find('#notice-num').text(length).show()
                    }else{
                        _this.$el.find('#notice-num').hide()
                    }
                } else {
                    _this.$el.find('#notice-num').hide()
                }
            })
        },
        logout: function () {
            ajax.get('logout.do').success(function (resp) {
                if (!resp.resultCode) {
                    session.clear();
                    LDFW.navigate('index')
                }
            })
        },
        unbind: function () {
            const _this = this
            $.confirm('您确定要解除绑定吗', function () {
                    ajax.post('unbind.do',{
                        wx_no:_this.model.get('wx_no')
                    }).success(function (resp) {
                        if (!resp.resultCode) {
                            $.toast('解绑成功', 3000);
                            _this.$el.find('a[operate="unbind"]').hide()
                            _this.$el.find('a[operate="bind"]').show()
                        }
                    })
                }, function () {
                }
            )
        }
    })
})
